<template>
	<view>
		<image src="/static/zhuce.png" mode="widthFix" class="image"></image>
		<view class="bgfff bgt mt-130 posire flex-ju-c">
			<image mode="widthFix" class="image width80 pt50" src="/static/zhucetxt.png"></image>
		</view>
		<view class="bgfff pt50 posire">
			<view class="con ">
				<view class="con">
					<input class="bgF6F7F8 ra20 pg25" maxlength="11" placeholder-style="color:#999;font-size:27rpx;" v-model="form.phone" placeholder="请输入手机号"/>
					<view  class=" mt30 bgF6F7F8 ra20 posire pg25">
						<!-- <view  class="copde flex-ju-c size27 posiab zindex50 right50 ">发送验证码</view> -->
						<view @click="yanzhengma" v-if="!butdisabled" class="copde flex-ju-c size27 posiab zindex50 right50 ">发送验证码</view>
						<view v-else class="copde flex-ju-c size27 posiab zindex50 right50">已发送 {{ codetxt }}</view>
						<input class="   " placeholder-style="color:#999;font-size:27rpx;" v-model="form.phone_code" placeholder="请输入验证码" />
					</view>
					<input class="bgF6F7F8 ra20 pg25 mt30" type="password" v-model="form.password"  placeholder-style="color:#999;font-size:27rpx;" placeholder="请输入登录密码"/>
					<input class="bgF6F7F8 ra20 pg25 mt30" type="password" v-model="form.password2" placeholder-style="color:#999;font-size:27rpx;" placeholder="确认密码"/>
					<input class="bgF6F7F8 ra20 pg25 mt30" v-model="form.invite_code" placeholder-style="color:#999;font-size:27rpx;" placeholder="请输入邀请码(选填)"/>
					
					<view @click="navto('login')" class="mt30 flex-row flex size26">
						<view>有账号，去登录</view>
					</view> 
					
						<view class="flex-ju-c mt100">
							<view class="flex-a-i color333 size24">
								<label class="flex-a-i">
									<radio @click="radioChange" color="#000" :checked="falg" value="1" style="transform:scale(0.7)" />
									我已阅读并同意
								</label>
								<text @click="navto('/pages/agreement?xieyis=1')">《用户协议》</text><text @click="navto('/pages/agreement?xieyis=2')">《隐私协议》</text>
							</view>
						</view>
					<view class="flex-ju-c mt20 pb30">
						<view @click="taplogin" class="flex-ju-c wh611-100 bg000 colorfff ra20 bold size30">注册</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type:1,
				falg:true,
				form:{},
				butdisabled:false,
				codetxt:60,
				timer:""
			}
		},
		onShow() {
		
		},
		onLoad(e) {
			
			if (e.invite_code) {
				this.form.invite_code = e.invite_code
			}
		},
		methods: {
			 yanzhengma(){
				 
				 
					if (!this.form.phone) {
						uni.showToast({
							title:"请输入手机号",
							icon:"none"
						})
						return
					}
					if (this.form.phone.trim().length != 11) {
						uni.showToast({
							title:"手机号错误",
							icon:"none"
						})
						return
					}
					this.http('phone-code', {
						phone: this.form.phone,
						value: 'reg',
					}, 'post').then(res => {
						uni.showToast({
							title:"发送成功",
							icon:"none"
						})
						this.butdisabled = true
						this.codetxt = 60
						this.timer = setInterval(() => {
							this.codetxt--
							if (this.codetxt < 1) {
								this.codetxt = 1
								clearInterval(this.timer)
								this.butdisabled = false
							}
						}, 1000)
					})
				},
			radioChange(e) {
				this.falg= !this.falg
			},
			denglu(index) {
				this.type = index
				this.form.phone_code =''
				this.form.password =''
			},
			 taplogin(){
				
					if (!this.form.phone) {
						uni.showToast({
							title:"请输入手机号",
							icon:"none"
						})
						return
					}
					if (this.form.phone.trim().length != 11) {
						uni.showToast({
							title:"手机号错误",
							icon:"none"
						})
						return
					}
					if (!this.form.phone_code) {
						uni.showToast({
							title:"请输入验证码",
							icon:"none"
						})
						return
					}
					if (!this.form.password) {
						uni.showToast({
							title:"请输入密码",
							icon:"none"
						})
						return
					}
					
					if(this.form.password != this.form.password2){
						uni.showToast({
							title:"密码不一致",
							icon:"none"
						})
						return
					}
					
					
					if (!this.falg) {
						uni.showToast({
							title:"请勾选协议条款",
							icon:"none"
						})
						return
					}
					
					
					
					this.http('reg', this.form,'post').then(res => {
						uni.showToast({
							title:"注册成功",
							icon:"none"
						})
						uni.reLaunch({
							url: "/pages/login"
						})
					})
				}
		}
	}
</script>


<style>
.bgt{
	border-top-right-radius: 50rpx;
	border-top-left-radius: 50rpx;
}
</style>
